package com.dyuloon.controller;

import com.dyuloon.entity.Client;
import com.dyuloon.entity.ConsumeClient;
import com.dyuloon.entity.RechargeClient;
import com.dyuloon.from.SearchForm;
import com.dyuloon.service.SaveMoneyService;
import com.dyuloon.util.ResultVOUtil;
import com.dyuloon.vo.PageVO;
import com.dyuloon.vo.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/saveMoney")
public class SaveMoneyController {
    @Autowired
    private SaveMoneyService saveMoneyService;


    //查询客户
    @GetMapping
    public ResultVO selectClient(SearchForm searchForm) {
        PageVO pageVO = this.saveMoneyService.selectClient(searchForm);
        return ResultVOUtil.success(pageVO,"查询成功！");
    }
    //开户（新增客户）
    @PostMapping("/openAccount")
    public ResultVO openAccount(@RequestBody Client client) {
        ResultVO resultVO =this.saveMoneyService.openAccount(client);
        return resultVO;
    }
    //充值（修改余额）
    @PutMapping("/recharge")
    public ResultVO recharge(@RequestBody RechargeClient rechargeClient){
        ResultVO resultVO = this.saveMoneyService.recharge(rechargeClient);
        return resultVO;
    }
    //消费
    @PutMapping("/consume")
    public ResultVO consume(@RequestBody ConsumeClient consumeClient){
        ResultVO resultVO = this.saveMoneyService.consume(consumeClient);
        return resultVO;
    }
    //销户(未测试）
    @DeleteMapping("/deleteClient/{id}")
    public ResultVO deleteClient(@PathVariable Integer id){
        boolean remove = this.saveMoneyService.removeById(id);
        ResultVO resultVO = remove ? ResultVOUtil.success(null,"删除成功！") : ResultVOUtil.fail("删除失败！");
        return resultVO;
    }
}
